
//% color="#ef784c" iconWidth=50 iconHeight=40
namespace pyttsx3{

    
    //% block="pyttsx3 begin " blockType="command"
    export function pyttsx3_Iint(parameter: any, block: any) {

        Generator.addImport(`import pyttsx3\n`)
        Generator.addCode("engine = pyttsx3.init()")
          
    }
    // //% block="pyttsx3_Iintsetvoice[VOICE]" blockType="command"
    // //% VOICE.shadow="number"   VOICE.defl=0
    // export function pyttsx3_Iintsetvoice(parameter: any, block: any) {

    //     let voice=parameter.VOICE.code
    //     Generator.addCode(`voices = engine.getProperty('voices')`)
    //     Generator.addCode(`engine.setProperty('voice',voices[${voice}].id)`)

    // } 
    //% block="pyttsx3_Iintsetvolume[VOLUME]" blockType="command"
    //% VOLUME.shadow="range"   VOLUME.params.min=0    VOLUME.params.max=100   VOLUME.defl=50
    export function pyttsx3_Iintsetvolume(parameter: any, block: any) {

        let volume=parameter.VOLUME.code
        volume = volume /100
        Generator.addCode(`engine.setProperty('volume',${volume})`)
  
    } 
    //% block="pyttsx3_Iintsetrate[RATE]" blockType="command"
    //% RATE.shadow="range"   RATE.params.min=0    RATE.params.max=200   RATE.defl=200
    export function pyttsx3_Iintsetrate(parameter: any, block: any) {

        let rate=parameter.RATE.code
        Generator.addCode(`engine.setProperty('rate',${rate})`)
    } 

    //% block="pyttsx3_Iintsay[STR]" blockType="command"
    //% STR.shadow="string"   STR.defl="你好呀"  
    export function pyttsx3_Iintsay(parameter: any, block: any) {
        let str=parameter.STR.code
        Generator.addCode(`engine.say(${str})`)
        Generator.addCode(`engine.runAndWait()`)

        
    } 

    //% block="pyttsx3_Iint [STR] save_file[FILE]" blockType="command"
    //% STR.shadow="string"   STR.defl="你好呀" 
    //% FILE.shadow="string"   FILE.defl="test"  
    export function pyttsx3_Iintsave_file(parameter: any, block: any) {
        let str=parameter.STR.code
        let file=parameter.FILE.code
        Generator.addCode(`engine.save_to_file(${str}, ${file}+'.mp3')`)
        Generator.addCode(`engine.runAndWait()`)

        
    } 


}
